/**
 * 
 */
package org.xlab.baseframework.web.data;

import org.xlab.baseframework.domain.enumerate.EnumLogLevel;
import org.xlab.baseframework.domain.query.SystemLogQueryObject;

import com.vaadin.data.Item;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;

/**
 * @author makubex
 * 
 */
public class LogSearchFormFieldFactory extends DefaultFieldFactory {

	/**
	 * @serialField
	 */
	private static final long serialVersionUID = 6135665506059653215L;

	private ComboBox min_logLevel = new ComboBox(
			SystemLogQueryObject.FIELD_MIN_LOGLEVEL);
	private ComboBox max_logLevel = new ComboBox(
			SystemLogQueryObject.FIELD_MAX_LOGLEVEL);

	/**
	 * <p>
	 * 默认构造函数
	 * </p>
	 */
	public LogSearchFormFieldFactory() {
		super();
		this.min_logLevel.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS);
		this.min_logLevel.setNullSelectionAllowed(false);
		this.min_logLevel.setItemCaptionPropertyId(SystemLogQueryObject.FIELD_MIN_LOGLEVEL);
		this.min_logLevel.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_PROPERTY);
		this.max_logLevel.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS);
		this.max_logLevel.setNullSelectionAllowed(false);
		this.max_logLevel.setItemCaptionPropertyId(SystemLogQueryObject.FIELD_MIN_LOGLEVEL);
		this.max_logLevel.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_PROPERTY);
		for (EnumLogLevel l : EnumLogLevel.values()) {
			this.min_logLevel.addItem(l);
			this.max_logLevel.addItem(l);
		}
	}

	/**
	 * @see com.vaadin.ui.DefaultFieldFactory#createField(com.vaadin.data.Item,
	 *      java.lang.Object, com.vaadin.ui.Component)
	 */
	public Field createField(Item item, Object propertyId, Component uiContext) {
		if (propertyId.equals(SystemLogQueryObject.FIELD_MIN_LOGLEVEL)) {
			return this.min_logLevel;
		} else if (propertyId.equals(SystemLogQueryObject.FIELD_MAX_LOGLEVEL)) {
			return this.max_logLevel;
		} else {
			Field f = super.createField(item, propertyId, uiContext);
			return f;
		}
	}
}
